
package com.kanjian.music.activity;

import com.kanjian.music.R;
import com.kanjian.music.api.ApiRequestManager;
import com.kanjian.music.constants.IntentConstants;
import com.kanjian.music.entity.Live;
import com.kanjian.music.network.HttpLoader;
import com.kanjian.music.view.CircleImageView;
import com.kanjian.music.volley.VolleyQueue;

import android.os.Bundle;
import android.support.v4.app.LoaderManager.LoaderCallbacks;
import android.support.v4.content.Loader;
import android.widget.TextView;

/**
 * 直播预告
 * 
 * @author xuyanjun
 */
public class NextLiveActivity extends BaseActivity implements LoaderCallbacks<String> {

    private String mLiveId;

    private TextView mTv_musicianName;

    private TextView mTv_liveName;

    private TextView mTv_liveTime;

    private TextView mTv_liveDesc;

    private CircleImageView mIv_musicianPic;

    @Override
    protected void onCreate(Bundle arg0) {
        setContentView(R.layout.activity_next_live);
        super.onCreate(arg0);
        initView();
        Bundle args = new Bundle();
        args.putSerializable(IntentConstants.HTTPLOADERREQUESTPARAM,
                ApiRequestManager.getActivityDetailRequest(mLiveId));
        getSupportLoaderManager().restartLoader(0, args, this);
    }

    private void initView() {
        Bundle b = getIntent().getExtras();
        mLiveId = b.getString(IntentConstants.LIVEID);
        mTv_musicianName = (TextView) findViewById(R.id.next_live_musician_name);
        mTv_liveName = (TextView) findViewById(R.id.next_live_live_name);
        mTv_liveTime = (TextView) findViewById(R.id.next_live_live_time);
        mTv_liveDesc = (TextView) findViewById(R.id.next_live_live_desc);
        mIv_musicianPic = (CircleImageView) findViewById(R.id.next_live_musician_pic);
    }

    @Override
    public Loader<String> onCreateLoader(int id, Bundle args) {
        return new HttpLoader(this, args);
    }

    @Override
    public void onLoadFinished(Loader<String> loader, String data) {
        if (data != null) {
            Live live = Live.getLiveFromJson(data);
            if (live != null) {
                mTv_musicianName.setText(live.mUserName);
                mTv_liveName.setText(live.mActivityName);
                mTv_liveTime.setText(live.getDisplayTimeStr());
                mTv_liveDesc.setText(live.mLiveDesc);
                mIv_musicianPic.setImageUrl(live.mUserPic, VolleyQueue.getImageLoader());
            }
        }
    }

    @Override
    public void onLoaderReset(Loader<String> loader) {
    }

}
